<?php
/**
* Anything that needs scheduling can make use of this generic model.
*
* This is based wholly on the cron scheduling syntax.
* @link http://en.wikipedia.org/wiki/CRON_expression
*
* It provides the means to create simple or complex schedules, for example:
* 1. Monday 6th March 2010
* 2. Every Monday at 8pm
* 3. 5th of every month at 4.30pm
* 4. Third sunday of every month
* 5. Every Tuesday in November
* 6. Every 2nd Saturday
* 7. The Last Friday of November and December 2010
*
* Copyright (c) 2009 James Gauld <james@jamesgauld.net>
* This file is part of Scribble.
* @license http://www.scribblecms.co.uk/license.txt
*
* @package Scribble
*/
class ScheduleModel extends ScribbleModel {

	/**
	* Export the schedule as a JSON representation.
	*
	* @return string
	*/
	public function exportJson() {
		return json_encode((object)$this->getDbData());
	}

	/**
	* Set the schedule expression directly. Use this if you know how to write
	* cron schedules.
	*
	* @param string A cronjob schedule string
	* @return void
	*/
	public function expr($expr) {
		$expr = explode(" ", $expr);
		$nodes = explode(',', 'seconds,minutes,hours,monthdays,months,weekdays,years');
		foreach($expr as $k=>$v) {
			$this->dbData["expr_{$nodes[$k]}"] = $v;
		}
	}
}
?>